class Solution {
public:
    int minimumAddedInteger(vector<int>& nums1, vector<int>& nums2) {

        int x = -1010;
        multiset<int> arr1;
        for (int i = -1010; i <= 1010; i++)
        {
            // cout << "*****";
            for (auto y : nums1)
                arr1.insert(y + i);

            bool flag = true;
            for (auto y : nums2)
            {
                if (arr1.count(y) == 0)
                    flag = false;

                if (arr1.count(y) > 0)
                {
                    int cnt = arr1.count(y);
                    cnt--;
                    arr1.erase(y);

                    while (cnt)
                    {
                        cnt--;
                        arr1.insert(y);
                    }
                }


            }

            if (flag)
            {
                x = i;
                break;
            }
            arr1.clear();

        }
        return x;

    }
};